﻿#include "training.h"
#include "ui_training.h"
#include <QButtonGroup>
#include "userDataFormate.h"
#include "ccommunicateapi.h"
#include "gamecontrol.h"
Training::Training(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Training),
    isStart(false)
{
    ui->setupUi(this);

    QButtonGroup * gameBox = new QButtonGroup;
    // 设置是否互斥
    gameBox->setExclusive(true);
    // 将需要互斥的按钮全部添加到 QButtonGroup 中
    gameBox->addButton(ui->fishing_radioButton,0);
    gameBox->addButton(ui->hen_radioButton,1);
    gameBox->addButton(ui->bubble_radioButton,2);
    gameBox->addButton(ui->fishFront_radioButton,3);
    gameBox->addButton(ui->fishDown_radioButton,4);
    gameBox->addButton(ui->fishLeft_radioButton,5);
    gameBox->addButton(ui->fishRight_radioButton,6);

    QButtonGroup * angleBox = new QButtonGroup;
    // 设置是否互斥
    angleBox->setExclusive(true);
    // 将需要互斥的按钮全部添加到 QButtonGroup 中
    angleBox->addButton(ui->sixAngle_radioButton,0);
    angleBox->addButton(ui->twelveAngle_radioButton,1);

    QButtonGroup * timeBox = new QButtonGroup;
    // 设置是否互斥
    timeBox->setExclusive(true);
    // 将需要互斥的按钮全部添加到 QButtonGroup 中
    timeBox->addButton(ui->fiveMin_RadioButton,0);
    timeBox->addButton(ui->tenMin_RadioButton,1);
    timeBox->addButton(ui->fifMin_RadioButton,2);
    timeBox->addButton(ui->twentyMin_RadioButton,3);
    timeBox->addButton(ui->twentyFiveMin_RadioButton,4);
    timeBox->addButton(ui->thirtyMin_RadioButton,5);

    QButtonGroup * directionBox = new QButtonGroup;
    // 设置是否互斥
    directionBox->setExclusive(true);
    // 将需要互斥的按钮全部添加到 QButtonGroup 中
    directionBox->addButton(ui->front_RadioButton,0);
    directionBox->addButton(ui->back_RadioButton,1);
    directionBox->addButton(ui->left_RadioButton,2);
    directionBox->addButton(ui->right_RadioButton,3);

    QButtonGroup * difficultyBox = new QButtonGroup;
    // 设置是否互斥
    difficultyBox->setExclusive(true);
    // 将需要互斥的按钮全部添加到 QButtonGroup 中
    difficultyBox->addButton(ui->high_RadioButton,0);
    difficultyBox->addButton(ui->middle_RadioButton,1);
    difficultyBox->addButton(ui->low_RadioButton,2);


    QButtonGroup * resistanceBox = new QButtonGroup;
    // 设置是否互斥
    resistanceBox->setExclusive(true);
    // 将需要互斥的按钮全部添加到 QButtonGroup 中
    resistanceBox->addButton(ui->level1_Rbtn,0);
    resistanceBox->addButton(ui->level2_Rbtn,1);
    resistanceBox->addButton(ui->level3_Rbtn,2);
    resistanceBox->addButton(ui->level4_Rbtn,3);
    resistanceBox->addButton(ui->level5_Rbtn,4);
    resistanceBox->addButton(ui->level6_Rbtn,5);


    this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);


    ui->stackedWidget->setCurrentIndex(0);

    ui->fiveMin_RadioButton->setChecked(true);
    ui->fishing_radioButton->setChecked(true);
    ui->front_RadioButton->setChecked(true);
    ui->random_radioButton->setChecked(true);
    ui->level1_Rbtn->setChecked(true);
    ui->sixAngle_radioButton->setChecked(true);
    ui->high_RadioButton->setChecked(true);
}

Training::~Training()
{
    delete ui;
}


void Training::on_random_radioButton_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
}

void Training::on_startTrain_Btn_clicked()
{

    isStart = true;
    ST_GameParam st_gameParam;
    if(ui->fiveMin_RadioButton->isChecked())
        st_gameParam.gameTime=5;
    if(ui->tenMin_RadioButton->isChecked())
        st_gameParam.gameTime=10;
    if(ui->fifMin_RadioButton->isChecked())
        st_gameParam.gameTime=15;
    if(ui->twentyMin_RadioButton->isChecked())
        st_gameParam.gameTime=20;
    if(ui->twentyFiveMin_RadioButton->isChecked())
        st_gameParam.gameTime=25;
    if(ui->thirtyMin_RadioButton->isChecked())
        st_gameParam.gameTime=30;

    if(ui->fishing_radioButton->isChecked())
    {     st_gameParam.path = "./game/Fishing/PH002_Fishing.exe";
        st_trainReport.game=0;

    }
    if(ui->hen_radioButton->isChecked())
    {
        st_gameParam.path = "./game/HenLayEggs/PH008_HenLayEggs.exe";

        st_trainReport.game=1;
    }
    if(ui->bubble_radioButton->isChecked())
    {
        st_gameParam.path = "./game/AriBubbleTop/PH027_AriBubbleTop.exe";
        st_trainReport.game=2;
    }
    if(ui->fishFront_radioButton->isChecked())
    {
        st_gameParam.path = "./game/BubbleTop/PH010_BubbleTop.exe";
        st_trainReport.game=3;
    }
    if(ui->fishDown_radioButton->isChecked())
    {
        st_gameParam.path = "./game/BubbleBottom/PH011_BubbleBottom.exe";
        st_trainReport.game=4;
    }
    if(ui->fishLeft_radioButton->isChecked())
    {
        st_gameParam.path = "./game/BubbleLeft/PH012_BubbleLeft.exe";
        st_trainReport.game=5;

    }
    if(ui->fishRight_radioButton->isChecked())
    {
        st_gameParam.path = "./game/BubbleRight/PH013_BubbleRight.exe";
        st_trainReport.game=6;
    }


    if(ui->sixAngle_radioButton->isChecked())
        st_gameParam.maxAngle=6;

    if(ui->twelveAngle_radioButton->isChecked())
        st_gameParam.maxAngle=12;


    if(ui->front_RadioButton->isChecked())
        st_gameParam.direction=1;

    if(ui->back_RadioButton->isChecked())
        st_gameParam.direction=2;

    if(ui->left_RadioButton->isChecked())
        st_gameParam.direction=3;

    if(ui->right_RadioButton->isChecked())
        st_gameParam.direction=4;

    if(ui->random_radioButton->isChecked())
        st_gameParam.gameplay = tr("随机");
    if(ui->orient_radioButton->isChecked())
        st_gameParam.gameplay = tr("定向");

    if(ui->high_RadioButton->isChecked())
        st_gameParam.trainDifficulty= 2;
    if(ui->middle_RadioButton->isChecked())
        st_gameParam.trainDifficulty= 1;
    if(ui->low_RadioButton->isChecked())
        st_gameParam.trainDifficulty= 0;

    if(ui->level1_Rbtn->isChecked())
        st_gameParam.resistance=1;
    if(ui->level2_Rbtn->isChecked())
        st_gameParam.resistance=2;
    if(ui->level3_Rbtn->isChecked())
        st_gameParam.resistance=3;
    if(ui->level4_Rbtn->isChecked())
        st_gameParam.resistance=4;
    if(ui->level5_Rbtn->isChecked())
        st_gameParam.resistance=5;
    if(ui->level6_Rbtn->isChecked())
        st_gameParam.resistance=6;

    st_gameParam.game = st_trainReport.game;

    GameControl::getInstance()->setGamParam(st_gameParam);
}


void Training::on_orient_radioButton_clicked()
{

    ui->stackedWidget->setCurrentIndex(1);
}



void Training::slotReceiveData(ST_RealParam st_realParam)
{
    if(isStart)
    {
        GameControl::getInstance()->sendCurrentAngleToGame(st_realParam.xAngle,st_realParam.yAngle);
    }
}

void Training::changeEvent(QEvent* event)
{
    switch (event->type())
    {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        QWidget::changeEvent(event);
        break;
    }
}
